package com.mj.app.health.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.mj.app.health.MyApplication;
import com.mj.app.health.R;

/**
 * ========================================
 * Created by 郝赫 on 2017/10/11.
 * ========================================
 */

public class CommonNoticeDialogSingle extends Dialog{

    private Context context;
    private TextView dia_title, dia_msg, dia_ok;
    private String titleTxt, msgTxt, sureTxt;
    private ICommonDialogSingle dialogSingle;

    public void setDialogSingle(ICommonDialogSingle dialogSingle){
        this.dialogSingle = dialogSingle;
    }

    public CommonNoticeDialogSingle(@NonNull Context context) {
        this(context, R.style.DarkFullScreenDialog);
        this.context = context;

        init();
    }

    public CommonNoticeDialogSingle(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        this.context = context;

        init();
    }

    private void init() {

        View rootView = LayoutInflater.from(context).inflate(R.layout.dialog_common_single_btn, null);
        setContentView( rootView);

        dia_msg = rootView.findViewById(R.id.dia_msg);
        dia_title = rootView.findViewById(R.id.dia_title);
        dia_ok = rootView.findViewById(R.id.dia_ok);
        setCancelable(true);
        setCanceledOnTouchOutside(true);

        if(getTitleTxt() != null && !"".equals(getTitleTxt())){
            dia_title.setText(getTitleTxt());
        }
        if(getMsgTxt() != null && !"".equals(getMsgTxt())){
            dia_msg.setText(getMsgTxt());
        }
        if(getSureTxt() != null && !"".equals(getSureTxt())){
            dia_ok.setText(getSureTxt());
        }

        Window window = getWindow();
        window.setLayout((int) (MyApplication.getScreenWidth()*0.8), ViewGroup.LayoutParams.WRAP_CONTENT);
        window.setWindowAnimations(R.style.DialogBottomAnimation);

        dia_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(dialogSingle!= null)
                    dialogSingle.onSingleSurePressed();

                dismiss();
            }
        });
    }

    public String getTitleTxt() {
        return titleTxt;
    }

    public void setTitleTxt(String titleTxt) {
        this.titleTxt = titleTxt;
        dia_title.setText(titleTxt);
    }

    public String getMsgTxt() {
        return msgTxt;
    }

    public void setMsgTxt(String msgTxt) {
        this.msgTxt = msgTxt;
        dia_msg.setText(msgTxt);
    }

    public String getSureTxt() {
        return sureTxt;
    }

    public void setSureTxt(String sureTxt) {
        this.sureTxt = sureTxt;
        dia_ok.setText(sureTxt);
    }
}
